/**
 * 请假申请管理初始化
 */
var LeaveApply = {
    id: "LeaveApplyTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
LeaveApply.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            /*{title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle'},*/
            {title: '请假人', field: 'userId', visible: true, align: 'center', valign: 'middle'},
            {title: '请假类型', field: 'leaveTypeId', visible: true, align: 'center', valign: 'middle'},
            {title: '请假开始时间', field: 'startDate', visible: true, align: 'center', valign: 'middle'},
            {title: '请假天数', field: 'days', visible: true, align: 'center', valign: 'middle'},
            {title: '请假结束时间', field: 'endDate', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'remarks', visible: true, align: 'center', valign: 'middle'},
            {title: '是否通过（1）不通过（2）通过', field: 'approveStatus', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
LeaveApply.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        LeaveApply.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加请假申请
 */
LeaveApply.openAddLeaveApply = function () {
    var index = layer.open({
        type: 2,
        title: '添加请假申请',
        area: ['1000px', '500px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/leaveApply/leaveApply_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看请假申请详情
 */
LeaveApply.openLeaveApplyDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '请假申请详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/leaveApply/leaveApply_update/' + LeaveApply.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除请假申请
 */
LeaveApply.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/leaveApply/delete", function (data) {
            Feng.success("删除成功!");
            LeaveApply.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("leaveApplyId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询请假申请列表
 */
LeaveApply.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    LeaveApply.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = LeaveApply.initColumn();
    var table = new BSTable(LeaveApply.id, "/leaveApply/list", defaultColunms);
    table.setPaginationType("client");
    LeaveApply.table = table.init();
});
layui.use('laydate', function() {
    var laydate = layui.laydate;
    laydate.render({
        elem : '#begin',
        max : getNowFormatDate()
    });
    laydate.render({
        elem : '#end',
        max : getNowFormatDate()
    });
});